package com.bjqh.edu.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bjqh.edu.Base.AppConstants;
import com.bjqh.edu.Bean.Orderdetails;
import com.bjqh.edu.R;
import com.bjqh.edu.UI.Activity.StudentPersonal.AlreadyDetailsActivity;
import com.bjqh.edu.UI.Activity.StudentPersonal.CanceledDetailActivity;
import com.bjqh.edu.UI.Activity.StudentPersonal.PendingDetailActivity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/9/12.
 */

public class CumulativeClassAdapter extends BaseAdapter {

    private List<Orderdetails.DataBean> list;
    private Context ctx;
    private ViewHolder holder;
    Orderdetails.DataBean dataBean;

    public CumulativeClassAdapter(Context ctx, List<Orderdetails.DataBean> list) {
        this.ctx = ctx;
        this.list = list;

    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View view, ViewGroup parent) {

        if (view == null) {
            view = LayoutInflater.from(ctx).inflate(R.layout.item_cumulative_class, null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.tvTime.setText( AppConstants.times(list.get(position).getTime()));
        holder.tvContent.setText(list.get(position).getCoursename() + "," + list.get(position).getCoursedes());
        holder.rlDe.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               dataBean= list.get(position);
                if(list.get(position).getStatus()==0)
                {
                    Intent intent = new Intent();
                    Bundle bundle=new Bundle();
                    bundle.putParcelable("data", dataBean);
                    intent.setClass(ctx, AlreadyDetailsActivity.class);
                    intent.putExtra("bundle", bundle);
                    ctx.startActivity(intent);

                }
                else if(list.get(position).getStatus()==1)
                {
                    Intent intent = new Intent();
                    Bundle bundle=new Bundle();
                    bundle.putParcelable("data", dataBean);
                    intent.setClass(ctx, CanceledDetailActivity.class);
                    intent.putExtra("bundle", bundle);
                    ctx.startActivity(intent);

                }
                else if(list.get(position).getStatus()==4)
                {
                    Intent intent = new Intent();
                    Bundle bundle=new Bundle();
                    bundle.putParcelable("data", dataBean);
                    intent.setClass(ctx, PendingDetailActivity.class);
                    intent.putExtra("bundle", bundle);
                    ctx.startActivity(intent);

                }

            }
        });
        return view;
    }



    static class ViewHolder {
        @BindView(R.id.tv_content)
        TextView tvContent;
        @BindView(R.id.rl_de)
        RelativeLayout rlDe;
        @BindView(R.id.tv_time)
        TextView tvTime;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }

    }
}
